package com.junsi.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
/**
 * 审批控制器
 */
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.junsi.bean.Approve;
import com.junsi.bean.ApproveTail;
import com.junsi.bean.ContractApprove;
import com.junsi.bean.Salestage;
import com.junsi.bean.Staff;
import com.junsi.service.ApproveService;
import com.junsi.service.ApproveTailService;
import com.junsi.service.ContractApproveService;
import com.junsi.service.SalestageService;
import com.junsi.service.StaffSerivce;
import com.junsi.util.InteractiveUtil;
import com.junsi.util.PageUtil;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("/approve")
public class ApproveController {
	@Autowired
	private ContractApproveService contractApproveService; // 合同审批
	@Autowired
	private ApproveService approveService; // 审批
	@Autowired
	private ApproveTailService apperoveTailService;// 审批跟踪
	@Autowired
	private StaffSerivce staffSerivce;
	@Autowired
	private SalestageService salestageService;
	Logger logger = Logger.getRootLogger();

	@RequestMapping("/Findnoapprove") // 未批准查询
	public ModelAndView Findnoapprove(HttpServletResponse response, HttpServletRequest request) {
		ModelAndView modelAndView = new ModelAndView();
		Staff staff = ((Staff) request.getSession().getAttribute("staff"));
		List<ContractApprove> ContractApprove = contractApproveService.listAll();// 合同审批
		List<ApproveTail> approveTails = apperoveTailService.listAll();
		List<Staff> staffs = staffSerivce.findByAll();
		String type = null;

		String approvalState = null;
		String username = null;// 审批人
		String approvesId = null;
		String acontractApproveId = null;
		List<Map<String, String>> array = new ArrayList<Map<String, String>>();
		for (ApproveTail approveTail : approveTails) {
			Map<String, String> map = new HashMap<String, String>();
			List<Approve> approves = approveService.findapproveRoleId(staff.getStaff_name(),
					approveTail.getApproveId().toString());
			System.out.println(approves.size());
			if (approves.size() != 0) {
				for (Approve a : approves) {
					approvesId = a.getApproveid().toString();
					acontractApproveId = a.getAcontractApproveId();
				}
				String[] approverUsername = approveTail.getApproverId().split(",");
				for (int i = 0; i < approverUsername.length; i++) {
					for (Staff s : staffs) {
						String id = s.getStaff_id().toString();
						if (approverUsername[i].equals(id)) {
							if (username == null) {
								username = s.getStaff_name();
							} else {
								username += "," + s.getStaff_name();
							}
						}
					}

				}
				for (ContractApprove contractApprove2 : ContractApprove) {
					String acontractApproveid = "";
					acontractApproveid = contractApprove2.getContractApproveId().toString();
					if (acontractApproveId.equals(acontractApproveid)) {
						type = contractApprove2.getApproveType();// 类型

						approvalState = contractApprove2.getApprovalState();
					}
				}
				map.put("approveId", approvesId);// 編號
				map.put("ApproverId", username);// 审批人
				map.put("approvalState", approvalState);// 状态
				map.put("type", type);// 类型

				array.add(map);
				username = null;
			}
		}
		modelAndView.addObject("array", array);// 合同审批表
		modelAndView.setViewName("forward:/page/index.jsp");
		return modelAndView;
	}

	@RequestMapping("/alreadyapproveAll") // 以批准,不审批查询分页
	public void alreadyapproveAll(PageUtil page, String condition, HttpServletResponse response,
			HttpServletRequest request) {
		Staff staff = ((Staff) request.getSession().getAttribute("staff"));
		page.setPageSize(5);
		List<Approve> approvepages;
		if (condition != null && !"".equals(condition)) {
			Integer count = approveService.timeapproveCount(staff.getStaff_name(), condition.trim());
			page.setRowCount(count);
			approvepages = approveService.timefindByAllAlready(staff.getStaff_name(), page, condition.trim());
		} else {
			Integer count = approveService.approveCount(staff.getStaff_name());// 以批准,不审批查询分页
			page.setRowCount(count);
			approvepages = approveService.findByAllAlready(staff.getStaff_name(), page);// 审批
		}

		List<ContractApprove> ContractApprove = contractApproveService.listAll();// 合同审批
		String approvalState = null;
		String cooperator = null;// 合作单位
		String rPerson = null;// 负责人
		String clientelePhone = null;// 客户电话
		String serviceQQ = null;// 客服QQ
		String applyNature = null;// 申请性质
		String pCategory = null;// 产品类别
		String contractRate = null;// 合约比例
		String Imanager = null;// 招商经理
		String contractId = null;// 合同编号
		List<Map<String, String>> array = new ArrayList<Map<String, String>>();
		for (Approve approvepag : approvepages) {
			Map<String, String> map = new HashMap<String, String>();
			for (ContractApprove contractApprove2 : ContractApprove) {
				String acontractApproveid = contractApprove2.getContractApproveId().toString();
				if (approvepag.getAcontractApproveId().equals(acontractApproveid)) {
					List<Salestage> salestages = salestageService.listAll();
					for (Salestage arraySalestage : salestages) {
						String salestage = arraySalestage.getSaleStageId().toString();
						if (salestage.equals(contractApprove2.getpCategory())) {
							contractApprove2.setpCategory(arraySalestage.getSaleStageName());
						}
					}
					approvepag.setSenderId(contractApprove2.getUsername());// 发送人
					approvalState = approvepag.getApproveCondition();
					cooperator = contractApprove2.getCooperator();
					rPerson = contractApprove2.getrPerson();
					clientelePhone = contractApprove2.getClientelePhone();
					serviceQQ = contractApprove2.getServiceQQ();
					applyNature = contractApprove2.getApplyNature();
					pCategory = contractApprove2.getpCategory();
					contractRate = contractApprove2.getContractRate();
					Imanager = contractApprove2.getImanager();
					contractId = contractApprove2.getContractId();
				}
			}
			List<Staff> staffs = staffSerivce.findByAll();
			for (Staff s : staffs) {
				String id = s.getStaff_id().toString();
				if (id.equals(approvepag.getApproverID())) {
					approvepag.setApproverID(s.getStaff_name());
				}
			}
			map.put("Approvers", approvepag.getApproverID() == null ? "" : approvepag.getApproverID());// 审批人
			map.put("approveId", approvepag.getApproveid().toString());// 編號
			map.put("cooperator", cooperator == null ? "" : cooperator);// 合作单位
			map.put("rPerson", rPerson == null ? "" : rPerson);// 负责人
			map.put("clientelePhone", clientelePhone == null ? "" : clientelePhone);// 客户电话
			map.put("serviceQQ", serviceQQ == null ? "" : serviceQQ);// 客服QQ
			map.put("applyNature", applyNature == null ? "" : applyNature);// 申请性质
			map.put("pCategory", pCategory == null ? "" : pCategory);// 产品类别
			map.put("contractRate", contractRate == null ? "" : contractRate);// 合约比例
			map.put("Imanager", Imanager == null ? "" : Imanager);// 招商经理
			map.put("approvalState", approvalState);// 状态
			map.put("contractId", contractId == null ? "" : contractId);// 合同编号
			array.add(map);
		}
		response.setContentType("text/json; charset=UTF-8");
		InteractiveUtil.WriteJsonForPage(array, page, response);
	}

	@RequestMapping("/pageFindnoapprove") // 未批准分页查询
	public void pageFindnoapprove(PageUtil page, HttpServletResponse response, String condition,
			HttpServletRequest request) throws Exception {
		Staff staff = ((Staff) request.getSession().getAttribute("staff"));
		page.setPageSize(5);
		List<Approve> approvepages;
		if (condition != null && !"".equals(condition)) {
			Integer count = approveService.timefindCount(staff.getStaff_name(), condition.trim());
			page.setRowCount(count);
			approvepages = approveService.timefindByAllContractApprove(page, staff.getStaff_name(), condition.trim());
		} else {
			Integer count = approveService.findCount(staff.getStaff_name());//
			page.setRowCount(count);
			approvepages = approveService.findByAllContractApprove(staff.getStaff_name(), page);// 审批
		}

		List<ContractApprove> ContractApprove = contractApproveService.listAll();// 合同审批
		String approvalState = null;
		String cooperator = null;// 合作单位
		String rPerson = null;// 负责人
		String clientelePhone = null;// 客户电话
		String serviceQQ = null;// 客服QQ
		String applyNature = null;// 申请性质
		String pCategory = null;// 产品类别
		String contractRate = null;// 合约比例
		String Imanager = null;// 招商经理
		String contractId = null;// 合同编号
		List<Map<String, String>> array = new ArrayList<Map<String, String>>();
		for (Approve approvepag : approvepages) {
			Map<String, String> map = new HashMap<String, String>();
			for (ContractApprove contractApprove2 : ContractApprove) {
				String acontractApproveid = contractApprove2.getContractApproveId().toString();
				if (approvepag.getAcontractApproveId().equals(acontractApproveid)) {
					List<Salestage> salestages = salestageService.listAll();
					for (Salestage arraySalestage : salestages) {
						String salestage = arraySalestage.getSaleStageId().toString();
						if (salestage.equals(contractApprove2.getpCategory())) {
							contractApprove2.setpCategory(arraySalestage.getSaleStageName());
						}
					}
					approvepag.setSenderId(contractApprove2.getUsername());// 发送人
					approvalState = contractApprove2.getApprovalState();
					cooperator = contractApprove2.getCooperator();
					rPerson = contractApprove2.getrPerson();
					clientelePhone = contractApprove2.getClientelePhone();
					serviceQQ = contractApprove2.getServiceQQ();
					applyNature = contractApprove2.getApplyNature();
					pCategory = contractApprove2.getpCategory();
					contractRate = contractApprove2.getContractRate();
					Imanager = contractApprove2.getImanager();
					contractId = contractApprove2.getContractId();
				}
			}
			List<Staff> staffs = staffSerivce.findByAll();
			for (Staff s : staffs) {
				String id = s.getStaff_id().toString();
				if (id.equals(approvepag.getApproverID())) {
					approvepag.setApproverID(s.getStaff_name());
				}
			}

			map.put("Approvers", approvepag.getApproverID() == null ? "" : approvepag.getApproverID());// 审批人
			map.put("approveId", approvepag.getApproveid().toString());// 編號
			map.put("cooperator", cooperator == null ? "" : cooperator);// 合作单位
			map.put("rPerson", rPerson == null ? "" : rPerson);// 负责人
			map.put("clientelePhone", clientelePhone == null ? "" : clientelePhone);// 客户电话
			map.put("serviceQQ", serviceQQ == null ? "" : serviceQQ);// 客服QQ
			map.put("applyNature", applyNature == null ? "" : applyNature);// 申请性质
			map.put("pCategory", pCategory == null ? "" : pCategory);// 产品类别
			map.put("contractRate", contractRate == null ? "" : contractRate);// 合约比例
			map.put("Imanager", Imanager == null ? "" : Imanager);// 招商经理
			map.put("approvalState", approvalState);// 状态
			map.put("contractId", contractId == null ? "" : contractId);// 合同编号
			array.add(map);
		}
		response.setContentType("text/json; charset=UTF-8");
		InteractiveUtil.WriteJsonForPage(array, page, response);

	}

	@RequestMapping("/countAllApprove") // 以批准,不审批查询所有分页//---------------------
	public void countAllApprove(PageUtil page, HttpServletResponse response, String condition,
			HttpServletRequest request) {
		page.setPageSize(5);
		List<Approve> approvepages;
		if (condition != null && !"".equals(condition)) {

			Integer count = approveService.timeCountAllApprove(condition.trim());// 以批准,不审批查询分页
			page.setRowCount(count);
			approvepages = approveService.timefindAllAudits(page, condition.trim());// 审批
		} else {
			Integer count = approveService.CountAllApprove();// 以批准,不审批查询分页
			page.setRowCount(count);
			approvepages = approveService.findAllAudits(page);// 审批
		}
		List<ContractApprove> ContractApprove = contractApproveService.listAll();// 合同审批
		String approvalState = null;
		String cooperator = null;// 合作单位
		String rPerson = null;// 负责人
		String clientelePhone = null;// 客户电话
		String serviceQQ = null;// 客服QQ
		String applyNature = null;// 申请性质
		String pCategory = null;// 产品类别
		String contractRate = null;// 合约比例
		String Imanager = null;// 招商经理
		String contractId = null;// 合同编号
		List<Map<String, String>> array = new ArrayList<Map<String, String>>();
		for (Approve approvepag : approvepages) {
			Map<String, String> map = new HashMap<String, String>();
			List<Staff> staffs = staffSerivce.findByAll();
			for (Staff s : staffs) {
				String id = s.getStaff_id().toString();
				if (id.equals(approvepag.getApproverID())) {
					approvepag.setApproverID(s.getStaff_name());
				}
			}
			for (ContractApprove contractApprove2 : ContractApprove) {
				String acontractApproveid = contractApprove2.getContractApproveId().toString();
				if (approvepag.getAcontractApproveId().equals(acontractApproveid)) {
					List<Salestage> salestages = salestageService.listAll();
					for (Salestage arraySalestage : salestages) {
						String salestage = arraySalestage.getSaleStageId().toString();
						if (salestage.equals(contractApprove2.getpCategory())) {
							contractApprove2.setpCategory(arraySalestage.getSaleStageName());
						}
					}
					approvepag.setSenderId(contractApprove2.getUsername());// 发送人
					approvalState = contractApprove2.getApprovalState();
					approvalState = contractApprove2.getApprovalState();
					cooperator = contractApprove2.getCooperator();
					rPerson = contractApprove2.getrPerson();
					clientelePhone = contractApprove2.getClientelePhone();
					serviceQQ = contractApprove2.getServiceQQ();
					applyNature = contractApprove2.getApplyNature();
					pCategory = contractApprove2.getpCategory();
					contractRate = contractApprove2.getContractRate();
					Imanager = contractApprove2.getImanager();
					contractId = contractApprove2.getContractId();
				}
			}
			map.put("approveId",
					approvepag.getApproveid().toString() == null ? "" : approvepag.getApproveid().toString());// 編號
			map.put("Approvers", approvepag.getApproverID() == null ? "" : approvepag.getApproverID());// 审批人
			map.put("senderId", approvepag.getSenderId() == null ? "" : approvepag.getSenderId());// 发送人
			map.put("cooperator", cooperator == null ? "" : cooperator);// 合作单位
			map.put("rPerson", rPerson == null ? "" : rPerson);// 负责人
			map.put("clientelePhone", clientelePhone == null ? "" : clientelePhone);// 客户电话
			map.put("serviceQQ", serviceQQ == null ? "" : serviceQQ);// 客服QQ
			map.put("applyNature", applyNature);// 申请性质
			map.put("pCategory", pCategory);// 产品类别
			map.put("contractRate", contractRate == null ? "" : contractRate);// 合约比例
			map.put("Imanager", Imanager == null ? "" : Imanager);// 招商经理
			map.put("approvalState", approvalState == null ? "" : approvalState);// 状态
			map.put("contractId", contractId == null ? "" : contractId);// 合同编号
			array.add(map);
		}
		response.setContentType("text/json; charset=UTF-8");
		InteractiveUtil.WriteJsonForPage(array, page, response);
	}

	@RequestMapping("/findApproveAmong") // 领导审批中查询
	public void findApproveAmong(PageUtil page, String condition, HttpServletResponse response,
			HttpServletRequest request) throws Exception {

		Staff staff = ((Staff) request.getSession().getAttribute("staff"));
		page.setPageSize(5);
		List<Approve> approves;
		if (condition != null && !"".equals(condition)) {

			Integer count = approveService.timeTApproveCount(staff.getStaff_id().toString(), condition.trim());
			page.setRowCount(count);
			approves = approveService.timeTApprove(staff.getStaff_id().toString(), page, condition.trim());
		} else {
			Integer count = approveService.tApproveCount(staff.getStaff_id().toString());//
			page.setRowCount(count);
			approves = approveService.tApprove(staff.getStaff_id().toString(), page);
		}

		List<ContractApprove> ContractApprove = contractApproveService.listAll();// 合同审批
		List<Map<String, String>> array = new ArrayList<Map<String, String>>();
		if (approves != null) {
			String approvalState = null;
			String cooperator = null;// 合作单位
			String rPerson = null;// 负责人
			String clientelePhone = null;// 客户电话
			String serviceQQ = null;// 客服QQ
			String applyNature = null;// 申请性质
			String pCategory = null;// 产品类别
			String contractRate = null;// 合约比例
			String Imanager = null;// 招商经理
			String contractId = null;// 合同编号
			for (Approve approvepag : approves) {// 用戶所要審核的表
				Map<String, String> map = new HashMap<String, String>();
				ApproveTail apperoveTails = apperoveTailService.findapprove(approvepag.getApproveRoleId());// 审核跟踪
				String[] arrayname = null;
				if (apperoveTails.getApproverId() != null && !"".equals(apperoveTails.getApproverId())) {
					arrayname = apperoveTails.getApproverId().split(",");
				}
				for (ContractApprove contractApprove2 : ContractApprove) {
					List<Salestage> salestages = salestageService.listAll();
					for (Salestage arraySalestage : salestages) {
						String salestage = arraySalestage.getSaleStageId().toString();
						if (salestage.equals(contractApprove2.getpCategory())) {
							contractApprove2.setpCategory(arraySalestage.getSaleStageName());
						}
					}
					String approveid = contractApprove2.getContractApproveId().toString();// 合同审批id
					if (approvepag.getAcontractApproveId().equals(approveid)) {
						approvepag.setSenderId(contractApprove2.getUsername());// 发送人
						approvalState = contractApprove2.getApprovalState();
						cooperator = contractApprove2.getCooperator();
						rPerson = contractApprove2.getrPerson();
						clientelePhone = contractApprove2.getClientelePhone();
						serviceQQ = contractApprove2.getServiceQQ();
						applyNature = contractApprove2.getApplyNature();
						pCategory = contractApprove2.getpCategory();
						contractRate = contractApprove2.getContractRate();
						Imanager = contractApprove2.getImanager();
						contractId = contractApprove2.getContractId();
						approvalState = contractApprove2.getApprovalState();
						break;
					}
				}
				map.put("approveId", approvepag.getApproveid().toString());// 編號
				map.put("ApproverId", approvepag.getSenderId() == null ? "" : approvepag.getSenderId());// 發送人
				map.put("cooperator", cooperator == null ? "" : cooperator);// 合作单位
				map.put("rPerson", rPerson == null ? "" : rPerson);// 负责人
				map.put("clientelePhone", clientelePhone == null ? "" : clientelePhone);// 客户电话
				map.put("serviceQQ", serviceQQ == null ? "" : serviceQQ);// 客服QQ
				map.put("applyNature", applyNature == null ? "" : applyNature);// 申请性质
				map.put("pCategory", pCategory == null ? "" : pCategory);// 产品类别
				map.put("contractRate", contractRate == null ? "" : contractRate);// 合约比例
				map.put("Imanager", Imanager == null ? "" : Imanager);// 招商经理
				map.put("contractId", contractId == null ? "" : contractId);// 合同编号
				map.put("approvalState", approvalState);// 状态
				if (arrayname != null) {
					if (arrayname[0].equals(approvepag.getApproverID())) {
						array.add(map);
					}
				}
			}

		}
		response.setContentType("text/json; charset=UTF-8");
		if (array.size() == 0 && page.getPageNum() == 1) {
			page.setPageCount(0);
		}
		InteractiveUtil.WriteJsonForPage(array, page, response);
	}

	@RequestMapping("/findContract") // 合同信息
	public void findContract(String approveId, HttpServletResponse response) {
		String id = approveId.trim();
		// 审批
		Approve approve = approveService.findById(Integer.valueOf(id));
		// 合同审批
		ContractApprove contractApprove = contractApproveService
				.findById(Integer.valueOf(approve.getAcontractApproveId()));
		// 产品类别
		List<Salestage> salestages = salestageService.listAll();
		for (Salestage arraySalestage : salestages) {
			String salestage = arraySalestage.getSaleStageId().toString();
			if (salestage.equals(contractApprove.getpCategory())) {
				contractApprove.setpCategory(arraySalestage.getSaleStageName());
			}
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
		String approveTime = null;
		if (approve.getApproveTime() != null) {
			approveTime = simpleDateFormat.format(approve.getApproveTime());
		}

		Map<String, String> map = new HashMap<String, String>();
		map.put("contractApproveId", contractApprove.getContractApproveId().toString());// 开户审批id
		map.put("pCategory", contractApprove.getpCategory());// 产品类别
		map.put("rPerson", contractApprove.getrPerson());// 负责人
		map.put("saleStageName", contractApprove.getSaleStageName());// 填写时间
		map.put("contractId", contractApprove.getContractId());// 合同编号
		map.put("username", contractApprove.getUsername());// 个人名称
		map.put("deposit", contractApprove.getDeposit());// 保证金
		map.put("contractTime", contractApprove.getContractTime());// 合同期限
		map.put("clientelePhone", contractApprove.getClientelePhone());// 客户电话
		map.put("serviceQQ", contractApprove.getServiceQQ());// 客服QQ
		map.put("contractContent", contractApprove.getContractContent());
		// 合同内容
		/*
		 * map.put("reserve", contractApprove.getReserve()); //其他预定
		 */ map.put("workLocation", contractApprove.getWorkLocation());// 现办公地址
		map.put("approvalState", contractApprove.getApprovalState());// 审批状态
		map.put("deposit", contractApprove.getDeposit());// 保证金
		map.put("activateTime", contractApprove.getActivateTime());
		// 激活时间
		/*
		 * map.put("preferential", contractApprove.getPreferential());//所属特会
		 */ map.put("approveOpinion", approve.getApproveOpinion());// 审批意见
		map.put("remarks", approve.getRemarks());// 说明
		map.put("approveTime", approveTime); // 审批时间
		map.put("applyNature", contractApprove.getApplyNature()); // 申请性质
		map.put("cooperator", contractApprove.getCooperator()); // 合作单位
		map.put("contractRate", contractApprove.getContractRate()); // 合约比例
		map.put("imanager", contractApprove.getImanager()); // 招商经理
		map.put("bLicenseimage", contractApprove.getbLicenseimage()); // 营业执照图片
		map.put("identityFront", contractApprove.getIdentityFront());// 身份证正面
		map.put("identityReverse", contractApprove.getIdentityReverse());// 身份证反面
		map.put("fileUploading", contractApprove.getFileUploading());// 文件
		JSONArray jsonArray = JSONArray.fromObject(map);
		response.setContentType("text/json; charset=UTF-8");
		try {
			response.getWriter().write(jsonArray.toString());
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/findcontractApprove") // 领导审批中查询詳細
	public void findcontractApprove(String approveId, HttpServletResponse response) {
		Approve approve = approveService.findById(Integer.valueOf(approveId));
		ContractApprove contractApprove = contractApproveService
				.findById(Integer.valueOf(approve.getAcontractApproveId()));
		JSONArray jsonArray = JSONArray.fromObject(contractApprove);
		response.setContentType("text/html; charset=UTF-8");
		try {
			response.getWriter().write(jsonArray.toString());
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 总页数,页码
	 * 
	 * @param staff
	 * @param file
	 * @return
	 */
	@RequestMapping("/count")
	public ModelAndView count(PageUtil page, HttpServletResponse response, HttpServletRequest request, String pageSize,
			String condition) {
		ModelAndView modelAndView = new ModelAndView();
		Staff staff = ((Staff) request.getSession().getAttribute("staff"));
		page.setPageSize(5);
		if (condition == null) {
			condition = "";
		}
		if (!"".equals(condition)) {
			if ("0".equals(pageSize)) { // 未审批
				Integer count = approveService.timefindCount(staff.getStaff_name(), condition.trim());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/htshenpi.jsp");
				return modelAndView;
			} else if ("1".equals(pageSize)) {// 已审批，审批失败
				Integer count = approveService.timeapproveCount(staff.getStaff_name(), condition.trim());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/yihtshenpi.jsp");
				return modelAndView;
			} else if ("2".equals(pageSize)) {// 查看审批完全部流程
				Integer count = approveService.timeCountAllApprove(condition.trim());
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/hetongshenpi.jsp");// ---------
			} else {// 领导审批
				Integer count = approveService.timeTApproveCount(staff.getStaff_id().toString(), condition.trim());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/inhtshenpi.jsp");
				return modelAndView;
			}
		} else {
			if ("0".equals(pageSize)) { // 未审批
				Integer count = approveService.findCount(staff.getStaff_name());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/htshenpi.jsp");
				return modelAndView;
			} else if ("1".equals(pageSize)) {// 已审批，审批失败
				Integer count = approveService.approveCount(staff.getStaff_name());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/yihtshenpi.jsp");
				return modelAndView;
			} else if ("2".equals(pageSize)) {// 查看审批完全部流程
				Integer count = approveService.CountAllApprove();
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.setViewName("forward:/pages/hetongshenpi.jsp");// ---------
			} else {// 领导审批
				Integer count = approveService.tApproveCount(staff.getStaff_id().toString());//
				page.setRowCount(count);
				modelAndView.addObject("PageCount", page.getPageCount());
				modelAndView.addObject("PageNum", page.getPageNum());
				modelAndView.addObject("condition", condition);
				modelAndView.setViewName("forward:/pages/inhtshenpi.jsp");
				return modelAndView;
			}
		}

		return modelAndView;

	}

}
